package core

import (
	"github.com/iris-contrib/middleware/jwt"
	"github.com/jinzhu/configor"
	"github.com/jinzhu/gorm"
	"github.com/kataras/iris/v12"
)

var (
	Router *iris.Application
	Config config
	DB     *gorm.DB
	JWT    *jwt.Middleware
)

func init() {
	if err := configor.Load(&Config, "./core/config.yml"); err != nil {
		panic(err)
	} else {
		if DB, err = Config.Database.Connect(); err != nil {
			panic(err)
		}
	}
	JWT = CreateJwtMiddleware()
	Router = iris.New()
	if Config.App.Env == "dev" {
		Router.Use(CreateYaagMiddleware())
	}
	Router.Use(CreateCorsMiddleware())
	SetOnErrorRouters(Router)

}
